package ru.tomsk.autovokzal.tools;

import android.os.Parcel;
import android.os.Parcelable;

public class TimeTableItem implements Parcelable, Cloneable {

	public static final Parcelable.Creator<TimeTableItem> CREATOR = new Creator<TimeTableItem>() {

		@Override
		public TimeTableItem[] newArray(int size) {
			return new TimeTableItem[size];
		}

		@Override
		public TimeTableItem createFromParcel(Parcel source) {
			return new TimeTableItem(source);
		}
	};
	private long id;
	private String startPoint;
	private String endPoint;
	private String numberOfRoute;
	private String depatureTime;
	private String dayOfFollowing;
	private double price;

	public TimeTableItem() {
		// TODO Auto-generated constructor stub
	}

	public TimeTableItem(Parcel in) {
		setDayOfFollowing(in.readString());
		setStartPoint(in.readString());
		setEndPoint(in.readString());
		setNumberOfRoute(in.readString());
		setDayOfFollowing(in.readString());
		setId(in.readLong());
		setPrice(in.readDouble());
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(getDayOfFollowing());
		dest.writeString(getStartPoint());
		dest.writeString(getEndPoint());
		dest.writeString(getNumberOfRoute());
		dest.writeString(getDayOfFollowing());
		dest.writeLong(getId());
		dest.writeDouble(getPrice());
	}

	public String getStartPoint() {
		return startPoint;
	}

	public void setStartPoint(String startPoint) {
		this.startPoint = startPoint;
	}

	public String getEndPoint() {
		return endPoint;
	}

	public void setEndPoint(String endPoint) {
		this.endPoint = endPoint;
	}

	public String getNumberOfRoute() {
		return numberOfRoute;
	}

	public void setNumberOfRoute(String numberOfRoute) {
		this.numberOfRoute = numberOfRoute;
	}

	public String getDepatureTime() {
		return depatureTime;
	}

	public void setDepatureTime(String depatureTime) {
		this.depatureTime = depatureTime;
	}

	public String getDayOfFollowing() {
		return dayOfFollowing;
	}

	public void setDayOfFollowing(String dayOfFollowing) {
		this.dayOfFollowing = dayOfFollowing;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	@Override
	public String toString() {
		return "TimeTableItem [id=" + id + ", startPoint=" + startPoint
				+ ", endPoint=" + endPoint + ", numberOfRoute=" + numberOfRoute
				+ ", depatureTime=" + depatureTime + ", dayOfFollowing="
				+ dayOfFollowing + ", price=" + price + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dayOfFollowing == null) ? 0 : dayOfFollowing.hashCode());
		result = prime * result
				+ ((depatureTime == null) ? 0 : depatureTime.hashCode());
		result = prime * result
				+ ((endPoint == null) ? 0 : endPoint.hashCode());
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result
				+ ((numberOfRoute == null) ? 0 : numberOfRoute.hashCode());
		long temp;
		temp = Double.doubleToLongBits(price);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result
				+ ((startPoint == null) ? 0 : startPoint.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TimeTableItem other = (TimeTableItem) obj;
		if (dayOfFollowing == null) {
			if (other.dayOfFollowing != null)
				return false;
		} else if (!dayOfFollowing.equals(other.dayOfFollowing))
			return false;
		if (depatureTime == null) {
			if (other.depatureTime != null)
				return false;
		} else if (!depatureTime.equals(other.depatureTime))
			return false;
		if (endPoint == null) {
			if (other.endPoint != null)
				return false;
		} else if (!endPoint.equals(other.endPoint))
			return false;
		if (id != other.id)
			return false;
		if (numberOfRoute == null) {
			if (other.numberOfRoute != null)
				return false;
		} else if (!numberOfRoute.equals(other.numberOfRoute))
			return false;
		if (Double.doubleToLongBits(price) != Double
				.doubleToLongBits(other.price))
			return false;
		if (startPoint == null) {
			if (other.startPoint != null)
				return false;
		} else if (!startPoint.equals(other.startPoint))
			return false;
		return true;
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		TimeTableItem newItem = new TimeTableItem();
		newItem.setId(getId());
		newItem.setDayOfFollowing(getDayOfFollowing());
		newItem.setDepatureTime(getDepatureTime());
		newItem.setEndPoint(getEndPoint());
		newItem.setNumberOfRoute(getNumberOfRoute());
		newItem.setPrice(getPrice());
		newItem.setStartPoint(getStartPoint());
		return newItem;
	}

	public boolean find(String find) {
		int index = getEndPoint().toLowerCase().indexOf(find.toLowerCase());
		return index == -1 ? false : true;

	}
}
